#pragma once
#include "../Memory/memory.h"
#include "../Memory/strings.h"
#include "ast.h"
using namespace XScript::Compile::Ast;
using namespace XScript::Memory;
using namespace XScript::Memory::Strings;
extern int yyparse();
extern FILE *yyin;
namespace XScript::Compile
{
	class CompilerTag;
	typedef CompilerTag* Compiler;

	class CompilerTag
	{
	public:
		int current_line_number;
		Block current_block;
		BlockMemoryManager*current_memory;
		RawStringManager*string_pool;
		StatementList statement_list;
		FunctionDefinitionList function_list;
		DeclarationList declaration_list;
		CompilerTag(BlockMemoryManager*memory, FILE*fp);
		FunctionDefinition SearchFunction(RawString name);
		Declaration SearchDeclaration(RawString identifier, Block block);
		void AppendFunction(FunctionDefinition fd);
		void Compile();
		void FixAst();
		static Compiler xscriptcall GetCurrent();
		static Compiler xscriptcall Create(FILE*fp);
		static void xscriptcall Dispose(Compiler compiler);
	private:
		void DoCompile();
		static Compiler& xscriptcall
			GetStaticCompilerRef();
	};

}